const { DataTypes } = require('sequelize')

const seq = require('../db/seq')
const Goods = require('./goods.model')

const Cart = seq.define('Cart', {
 goods_id: {
  type: DataTypes.INTEGER,
  allowNull: false,
  comment: '商品ID'
 },
 user_id: {
  type: DataTypes.INTEGER,
  allowNull: false,
  comment: '用户ID'
 },
 number: {
  type: DataTypes.INTEGER,
  allowNull: false,
  defaultValue: 1,
  comment: '商品数量'
 },
 selected: {
  type: DataTypes.BOOLEAN,
  allowNull: false,
  defaultValue: true,
  comment: '是否选中'
 }
})

// Cart.sync({ force: false })
// 创建外键,链接到Goods表中的goods_id,并且重命名为goods_info
Cart.belongsTo(Goods, { foreignKey: 'goods_id', as: 'goods_info' })

module.exports = Cart